package cn.longge.controller;

import cn.longge.entity.Result;
import cn.longge.entity.SysResource;
import cn.longge.service.ISysResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("manager/resource")
public class SysResourceController {
    @Autowired
    private ISysResourceService resourceService;

    @RequestMapping("list")
    public Result list(Long rid){
        SysResource sysResource = new SysResource();
        sysResource.setDelFlag("0");
        List<SysResource> select = resourceService.select(sysResource);
        Map<String, List<SysResource>> map = resourceService.selectByRid(rid);
        return new Result(true,"success",map);
    }

    @RequestMapping("selectByUid")
    public Result selectByUid(Long uid, HttpSession session){
        List<SysResource> sysResources = resourceService.selectByUid(uid);
        session.setAttribute("resources",sysResources);
        return new Result(true,"success",sysResources);
    }
}
